var msgMgr = new Object();
msgMgr.url = "https://2020cn.cn/hxsg/api/msg_mgr";
msgMgr.net = new Object();
msgMgr.net.sendMsg=function(uid, uname,msg, type,cb) {
    $.post(
        msgMgr.url,
        {
            "action": "msg_add",
            "user_id": uid,
            "user_name":uname,
            "content": msg,
            "type": type
        },
        function (res) {
            if(cb){
                cb();
            }

        }
    );
};

msgMgr.net.getMsgByType=function(type){
    $.post(
        msgMgr.url,
        {
            "action": "msg_get_by_type",
            "type": type
        },
    
        function (res) {
            var resobj = JSON.parse(res);
            var msgDiv = document.getElementById(getMsgidByType(type)+"-pane");
            if(resobj.code == "200"){
              $(msgDiv).children().remove();

                resobj.data.forEach(dobj => {
                    var newnode = $("<p>" + (dobj.timestamp).substring(11,19) + "&nbsp<span class='badge text-bg-danger'>" +dobj.user_name+ "</span>:" + dobj.content + "</p>")
                $(msgDiv).append(newnode);

                  })

            }else{
              $(msgDiv).children().remove();

                var newnode = $("<p>无消息</p>")
                $(msgDiv).prepend(newnode);
            }
        
          
        }
        );
}